//
//  AppDelegate.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/7/28.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        window?.makeKeyAndVisible()
        
//        print(MYLoginViewModel.shareInstance)
        /** 如果登录成功 */
        if MYLoginViewModel.shareInstance.isLogin {
            /** 到欢迎界面 */
            window?.rootViewController = MYWelcomeViewController()
        } else {
            window?.rootViewController = MYTabBarViewController()
        }
        
        /** 获取系统版本号 */
//        UIDevice.currentDevice().systemVersion
        
        /** 通知 */
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeRootViewController:", name: kNotificationChangeViewController, object: nil)
        
        /** 修改navigationItem的渲染色(修改全局的) */
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        
        return true
    }
    
    /** 更换控制器 */
    @objc private func changeRootViewController(noti: NSNotification) {
        
        if noti.object is MYOAuthViewController {
            window?.rootViewController = MYWelcomeViewController()
        } else {
            window?.rootViewController = MYTabBarViewController()
        }
    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

}

